package com.example.shiwuyouproject.ui.fragment.my.activity.adapter

import android.view.LayoutInflater
import android.widget.LinearLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.example.shiwuyouproject.R
import com.example.shiwuyouproject.ui.fragment.my.activity.bean.MyApplicationBean
import com.example.shiwuyouproject.utils.GlideUtils
import com.example.shiwuyouproject.utils.TimeUtils

class MyApplicationAdapter :
    BaseQuickAdapter<MyApplicationBean, BaseViewHolder>(R.layout.item_myapplication) {
    override fun convert(helper: BaseViewHolder, item: MyApplicationBean?) {
        helper.setText(R.id.tvTitle, item?.title)
            .setText(R.id.tvOrgName, item?.org_name)
            .setText(R.id.tvAddress, item?.show_address)
            .setText(
                R.id.tvWorkDay, item?.getWorkDayTitle() + " "
                        + TimeUtils.HourMM(item?.start_time) + "-"
                        + TimeUtils.HourMM(item?.end_time) + "   " + item?.stu_num + "人报名"
            )
            .setText(R.id.tvapplyTime, item?.apply_time)
        if (item?.status == "-1") {
            helper.setText(R.id.tvTypeMoney, "停止招聘")
            helper.getView<TextView>(R.id.tvTypeMoney).isSelected = false
        } else {
            helper.setText(R.id.tvTypeMoney, item?.fee_start_show + "元/小时")
            helper.getView<TextView>(R.id.tvTypeMoney).isSelected = true
        }
        if (item?.tags?.length == 0) {
            helper.setGone(R.id.llTags, false)
        } else {
            val myTagsView = helper.getView<LinearLayout>(R.id.llTags)
            if (item?.tags != null) {
                helper.setGone(R.id.llTags, true)
                val tagsLeng = item?.tags?.split(",")
                for (index in 0..tagsLeng?.size!!) {
                    val myItemView = LayoutInflater.from(mContext).inflate(R.layout.item_tags, null)
                    if (index != 0) {
                        myItemView.setPadding(10, 0, 0, 0)
                    } else {
                        myItemView.setPadding(0, 0, 0, 0)
                    }
                    val tvTitle: TextView = myItemView.findViewById(R.id.tvTagTitle)
                    tvTitle.text = tagsLeng[index]
                    myTagsView.addView(myItemView)
                }
            } else {
                helper.setGone(R.id.llTags, false)
            }
        }
        GlideUtils.fangImgPortrait(mContext, helper.getView(R.id.haderImg), item?.avatar!!)
    }
}